<template>
    <div>
        <div class="history">
            <div class="history_top">
                <h2>历史记录</h2>
                <van-icon name="delete-o" class="delIcon" @click="delhis" />
            </div>
            <div class="history_down">
                <van-tag v-for="(item,index) in historyKeywordList" :key="index" plain type="default"
                    @click="pushInputVal(item)">{{item}}</van-tag>
            </div>
        </div>
        <div class="history">
            <div class="history_top">
                <h2>热门搜索</h2>
            </div>
            <div class="history_down">
                <van-tag v-for="(item,index) in hotKeywordList" :key="index" plain
                    :type="item.is_hot?'danger':'default'" @click="pushInputVal(item.keyword)">{{item.keyword}}
                </van-tag>
            </div>
        </div>
    </div>
</template>

<script>
    import {
        ClearHistoryApi
    } from '@/request/api'
    export default {
        props: ["hotKeywordList", "historyKeywordList"],
        data() {
            return {


            }
        },
        methods: {
            // 清除历史记录
            delhis() {
                ClearHistoryApi().then(res => {
                    if (res.errno === 0) {
                        // console.log("成功了");
                        this.$emit("delhisFn")
                    }
                })
                
            },
            pushInputVal(val) {
                // console.log(val);
                this.$emit("listClickFn", 2, val)
            }
        }
    }
</script>

<style lang="less" scoped>
    .history {
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;

        .history_top {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 5px;

            .delIcon {
                font-size: 18px;
            }

            h2 {
                font-size: 18px;
            }
        }

        .history_down {
            .van-tag {
                margin-right: 10px;
                margin-bottom: 10px;
            }
        }
    }
</style>